package com.mdd.common.util.weifengqi.authorize;

import com.alibaba.fastjson.JSONObject;
import com.mdd.common.util.HttpUtils;
import com.mdd.common.util.ToolUtils;
import com.mdd.common.util.weifengqi.encryptionPassword.AESUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;

/**
 * 微风企H5授权工具类(获取企业基础信息授权rpa)
 */
@Slf4j
public class AuthorizeUtil {
    //请求路径
    public static final String url = "https://www.wfq2020.com/auth/#/authorization?webAuthorizeChannelCode=5lc98";
    public static final String url20250519 = "https://www.wfq2020.com/authorization/?channelCode=ts5lf";
//    public static final String url = "https://www.wfq2020.com/auth/#/authorization";
    //渠道身份
    public static final String webAuthorizeChannelCode="5lc98";
    public static final String channelCode20250519="ts5lf";
    //微风企获取企业原数据授权回调地址
    public static final String cburl="http://zhongduniot.com:8888/api/ws/basicInformationCallback";
    //微风企获取企业原数据采集完成回调地址
    public static final String cburlData="http://zhongduniot.com:8888/api/ws/basicInformationCollectionCallback";

    //获取企业基础/原信息---渠道编码号
    public static final String interfaceCode = "ef911dbc71ee40c494f10b0a64d722a1ks438";
    //获取企业基础/原信息---加密串
    public static final String secretKey = "fjx30gaP2uKSy0k2AbLGqFV4zUUWQS0y3AlTfF/7oP2LYQiIrYT2JJD39cq4vL+Q";

//https://www.wfq2020.com/authorization/?channelCode=ts5lf&cburl=https%3A%2F%2Fwww.baidu.com%2F%3ForgCode%3D1&message=T3BIcGVnVW54ZCswd2R3TC95UXVBdEVvOGZNNDg0UWhLVXVWc3EwZjkyWXpkSHh6MTVJMCtzNmhRVXl5bWRxTGpZa2lzVnQ1V0pFOTl3RXZwNUUvY09LWXpwa2FpMlBKN1oxRnpmQW1XWGhZajhSNFRjTGMzMldwVDBlcjdRVTk=

    public static void authorize(String messagePassword){
        //组装参数
        StringBuffer buffer = new StringBuffer().append(url20250519)
//                .append("&channelCode=").append(channelCode20250519)
                .append("&cburl=").append(cburl)
                .append("&message=").append(messagePassword);
        log.warn("加密信息为："+messagePassword);
        log.warn("请求路劲地址为："+buffer.toString());
        System.out.println("加密信息为："+messagePassword);
        System.out.println("请求路劲地址为："+buffer.toString());

        String result = HttpUtils.sendGet(buffer.toString());
        System.out.println(result);
    }

    public static void createParam(String companyName) {
        //message加密信息
        String messagePassword="";
        JSONObject message = new JSONObject();
        String orderNo = ToolUtils.randomString(36);
        message.put("orderNo", orderNo);
//        typeWay为空：（taxpayerId、companyName）必填其一
//        typeWay为1：authenticationMsg对象值必填（cognizantMobile 、cognizantName）
//        typeWay为2：firms数组必填 内部对象必填其一（companyName or taxpayerId）
//        typeWay为3：firms数组必填 内部对象必填其一（companyName or taxpayerId）且
//        authenticationMsg对象值必填（cognizantMobile 、cognizantName）
//        message.put("typeWay", null);
        message.put("companyName", companyName);
        try {
            messagePassword = AESUtils.encryptForSys(message);
        } catch (UnsupportedEncodingException e) {
            log.warn("加密失败", e);
            throw new RuntimeException(e);
        }
        log.warn("本次订单号为："+orderNo);
        log.warn("本次公司名称为："+companyName);
        System.out.println("本次订单号为："+orderNo);
        System.out.println("本次公司名称为："+companyName);
        authorize(messagePassword);

    }


    public static void main(String[] args) {
        createParam("北京共融联创科技有限公司");

    }






}
